package view;

import Bean.Room;
import control.RoomManagerControl;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class UpdateRoomDialog extends RootDialog
{

    RoomManagerControl rmControl = new RoomManagerControl();
    Room Room = new Room();
    view.RoomCategoryPanel panel;
    int choice;
    private JFrame window;

    public UpdateRoomDialog(view.RoomCategoryPanel panel, int choice, JFrame window)
    {
        initComponents();
        this.window = window;
        this.setTitle("Cập nhật phòng");
        this.panel = panel;
        this.choice = choice;
        jCBLoaiphong.removeAllItems();
        List<Room> list = rmControl.getRoomTypeName();
        for (Room obj_room : list)
        {
            jCBLoaiphong.addItem(obj_room.getTyperoom().toString());
        }
        Room = rmControl.getRoomName(choice);
        jTFTenphong.setText(Integer.toString(choice));
        jTFTenphong.setEnabled(false);
        jCBLoaiphong.setSelectedItem(Room.getTyperoom());
        jTFGiaphong.setText(Integer.toString(Room.getCostroom()));
        jCBTinhtrang.setSelectedItem(Room.getState());
        Init();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jLabel1 = new javax.swing.JLabel();
        jCBLoaiphong = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTFGiaphong = new javax.swing.JTextField();
        jCBTinhtrang = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jTFTenphong = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 102, 153));
        jLabel1.setText("Loại phòng");

        jCBLoaiphong.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jCBLoaiphong.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jCompoBox1ActionListener(evt);
            }
        });

        jLabel2.setForeground(new java.awt.Color(0, 102, 153));
        jLabel2.setText("Giá");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton1.setText("Cập nhật");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton1ActionListener(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 102, 153));
        jLabel3.setText("Tên phòng");

        jTFGiaphong.setEditable(false);
        jTFGiaphong.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTFGiaphong.setText(" ");

        jCBTinhtrang.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jCBTinhtrang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Đã thuê", "Còn trống" }));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(0, 102, 153));
        jLabel4.setText("Tình trạng");

        jTFTenphong.setEditable(false);
        jTFTenphong.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/update_room.png"))); // NOI18N

        jLabel6.setForeground(new java.awt.Color(0, 102, 153));
        jLabel6.setText("VNĐ/ngày");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2))
                                .addGap(30, 30, 30)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jCBLoaiphong, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTFGiaphong)
                                    .addComponent(jCBTinhtrang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTFTenphong, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTFTenphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCBLoaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTFGiaphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jCBTinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                .addGap(66, 66, 66))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 11, Short.MAX_VALUE)
                .addComponent(jLabel5))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCompoBox1ActionListener(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jCompoBox1ActionListener
    {//GEN-HEADEREND:event_jCompoBox1ActionListener
        String _choice = jCBLoaiphong.getSelectedItem().toString();
        jTFGiaphong.setText(Integer.toString(rmControl.getPriceOf(_choice)));
    }//GEN-LAST:event_jCompoBox1ActionListener

    private void jButton1ActionListener(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionListener
        Room.setTyperoom((String) jCBLoaiphong.getSelectedItem());
        Room.setState((String) jCBTinhtrang.getSelectedItem());
        Room.setName(Integer.parseInt(jTFTenphong.getText()));
        if (JOptionPane.showConfirmDialog(this, "Bạn chắc chắn muốn cập nhật?",
                "Cập nhật phòng", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
        {
            rmControl.editInformationOfRoom(Room);
            JOptionPane.showMessageDialog(null, "Cập nhật thành công");
        }
        panel.reset();
        window.setVisible(true);
        window.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionListener
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jCBLoaiphong;
    private javax.swing.JComboBox jCBTinhtrang;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTFGiaphong;
    private javax.swing.JTextField jTFTenphong;
    // End of variables declaration//GEN-END:variables
}
